﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace Himp.Platform
{
    public class LogEventDto
    {
        /// <summary>
        /// The event type (ie. error, log message, feature usage). Check <see cref="KnownTypes">Event.KnownTypes</see> for standard event types.
        /// </summary>
        public string? Type { get; set; }

        /// <summary>
        /// The event source (ie. machine name, log name, feature name).
        /// </summary>
        public string? Source { get; set; }

        /// <summary>
        /// The date that the event occurred on.
        /// </summary>
        public DateTimeOffset Date { get; set; }

        /// <summary>
        /// A list of tags used to categorize this event.
        /// </summary>
        public HashSet<string?>? Tags { get; set; } = [];

        /// <summary>
        /// The event message.
        /// </summary>
        public string? Message { get; set; }

        /// <summary>
        /// The geo coordinates where the event happened.
        /// </summary>
        public string? Geo { get; set; }

        /// <summary>
        /// The value of the event if any.
        /// </summary>
        public decimal? Value { get; set; }

        /// <summary>
        /// The number of duplicated events.
        /// </summary>
        public int? Count { get; set; }

        /// <summary>
        /// Optional data entries that contain additional information about this event.
        /// </summary>
        public Dictionary<string, object?>? Data { get; set; } = new();

        /// <summary>
        /// An optional identifier to be used for referencing this event instance at a later time.
        /// </summary>
        public string? ReferenceId { get; set; }


        private static readonly List<string> _exclusions = [KnownDataKeys.TraceLog];
       
        public static class KnownTypes
        {
            public const string Error = "error";
            public const string FeatureUsage = "usage";
            public const string Log = "log";
            public const string NotFound = "404";
            public const string Session = "session";
            public const string SessionEnd = "sessionend";
            public const string SessionHeartbeat = "heartbeat";
        }

        public static class KnownTags
        {
            public const string Critical = "Critical";
            public const string Internal = "Internal";
        }

        public static class KnownDataKeys
        {
            public const string Error = "@error";
            public const string SimpleError = "@simple_error";
            public const string RequestInfo = "@request";
            public const string TraceLog = "@trace";
            public const string EnvironmentInfo = "@environment";
            public const string UserInfo = "@user";
            public const string UserDescription = "@user_description";
            public const string Version = "@version";
            public const string Level = "@level";
            public const string Location = "@location";
            public const string SubmissionMethod = "@submission_method";
            public const string SubmissionClient = "@submission_client";
            public const string SessionEnd = "sessionend";
            public const string SessionHasError = "haserror";
            public const string ManualStackingInfo = "@stack";
        }
    }
}
